import Vue from "vue";
import Router from "vue-router";

/* Layout */

const login = (resolve) => require(["@/views/login"], resolve);
// const register = (resolve) => require(["@/views/register"], resolve);
// const index = (resolve) => require(["@/views/index"], resolve);
const index = (resolve) => require(["@/views/work/index"], resolve);
const titlePage = (resolve) => require(["@/views/titlePage"], resolve);
const profile = (resolve) =>
  require(["@/views/configuration/organization/user/profile/index"], resolve);
const authRole = (resolve) =>
  require(["@/views/configuration/organization/user/authRole"], resolve);
const authUser = (resolve) =>
  require(["@/views/configuration/organization/role/authUser"], resolve);
const dictData = (resolve) => require(["@/views/configuration/basicdata/dict/data"], resolve);
const editTable = (resolve) => require(["@/views/configuration/tool/gen/editTable"], resolve);
const jobLog = (resolve) => require(["@/views/maintenance/monitor/job/log"], resolve);
const roomUser = (resolve) => require(["@/views/configuration/park/roommsg/configuration"], resolve);
const esign = (resolve) => require(["@/views/esign/index"], resolve);
const statisticsBudgetDetail = (resolve) => require(["@/views/statistics/budgetDeclaration/detail"], resolve);
const statisticsBudgetUseDetail = (resolve) => require(["@/views/statistics/budgetUse/detail"], resolve);
Vue.use(Router);

import Layout from "@/layout";
import BigSLayout from "@/components/bigSLayout";
// import reLayout from "@/layout/reIndex"; // 暂时废弃

/**
 * Note: 路由配置项
 *
 * hidden: true                     // 当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true                 // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                  // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                  // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                  // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 * redirect: noRedirect             // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
 * name:'router-name'               // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
 * roles: ['admin', 'common']       // 访问路由的角色权限
 * permissions: ['a:a:a', 'b:b:b']  // 访问路由的菜单权限
 * meta : {
    noCache: true                   // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    title: 'title'                  // 设置该路由在侧边栏和面包屑中展示的名字
    icon: 'svg-name'                // 设置该路由的图标，对应路径src/assets/icons/svg
    breadcrumb: false               // 如果设置为false，则不会在breadcrumb面包屑中显示
    activeMenu: '/system/user'      // 当路由设置了该属性，则会高亮相对应的侧边栏。
  }
 */
// 解决Error: Redirected from “/login” to “/index” via a navigation guard.
const originalPush = Router.prototype.push;
Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject);
  return originalPush.call(this, location).catch((err) => err);
};
// 公共路由
export const constantRoutes = [
  {
    path: "/redirect",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "/redirect/:path(.*)",
        component: (resolve) => require(["@/views/redirect"], resolve),
      },
    ],
  },
  {
    path: "/",
    // component: reLayout,
    component: Layout,
    redirect: "/work/general",
    hidden: true,
    children: [
      {
        path: "/work/general",
        component: index,
        name: "General",
        meta: { title: "能效一览", icon: "international", affix: true },
      },
    ],
  },
  {
    path: "/login",
    component: login,
    hidden: true,
  },
  {
    path: "/visualization",
    component: BigSLayout,
    redirect: "visualization",
    children: [],
    hidden: true,
  },
  // {
  //   path: "/register",
  //   component: register,
  //   hidden: true,
  // },
  // {
  //   path: '/titlePage',
  //   component: titlePage,
  //   hidden: true,
  // },
  // {
  //   path: "/titlePage",
  //   // component: BigSLayout,
  //   component: titlePage,
  //   // redirect: "titlePage",
  //   // children: [
  //   //   {
  //   //     path: "",
  //   //     component: titlePage,
  //   //     name: "titlePage",
  //   //     meta: { title: "公共机构双控双碳数字管家" },
  //   //   },
  //   // ],
  //   hidden: true,
  //   meta: { title: "导航页", icon: "international", affix: true },
  // },
  // {
  //   path: "/",
  //   // component: reLayout,
  //   // component: titlePage,
  //   redirect: "/titlePage",
  //   hidden: true,
  //   children: [
  //     {
  //       path: "titlePage",
  //       component: titlePage,
  //       name: "titlePage",
  //       meta: { title: "导航页" },
  //     },
  //   ],
  // },
  {
    path: "/404",
    component: (resolve) => require(["@/views/error/404"], resolve),
    hidden: true,
  },
  {
    path: "/401",
    component: (resolve) => require(["@/views/error/401"], resolve),
    hidden: true,
  },
  {
    path: "/user",
    component: Layout,
    hidden: true,
    redirect: "noredirect",
    children: [
      {
        path: "profile",
        component: profile,
        name: "Profile",
        meta: { title: "个人中心", icon: "user" },
      },
    ],
  },
  {
    path: "/configuration/organization/users",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "authRole/:userId(\\d+)",
        component: authRole,
        name: "AuthRole",
        meta: { title: "分配角色", activeMenu: "/configuration/organization/user" },
      },
    ],
  },
  {
    path: "/configuration/organization/roles",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "authUser/:roleId(\\d+)",
        component: authUser,
        name: "AuthUser",
        meta: { title: "分配用户", activeMenu: "/configuration/organization/role" },
      },
    ],
  },
  {
    path: "/configuration/basicdata/dicts",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "index/:dictId(\\d+)",
        component: dictData,
        name: "Data",
        meta: { title: "字典数据", activeMenu: "/configuration/basicdata/dict" },
      },
    ],
  },
  {
    path: "/maintenance/monitor/jobs",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "index",
        component: jobLog,
        name: "JobLog",
        meta: { title: "调度日志", activeMenu: "/maintenance/monitor/job" },
      },
    ],
  },
  {
    path: "/configuration/tool/gens",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "index",
        component: editTable,
        name: "GenEdit",
        meta: { title: "修改生成配置", activeMenu: "/configuration/tool/gen" },
      },
    ],
  },
  {
    path: "/work/standingbook/commons",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "inspect",
        component: () => import("@/views/work/standingbook/common/inspect"),
        name: "CarbonInspect",
        meta: { title: "碳排核查", activeMenu: "/work/standingbook/common" },
      },
    ],
  },
  {
    path: "/resource/park/parkmsgs",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "detail",
        component: () => import("@/views/configuration/park/parkmsg/components/detail"),
        name: "parkMsgdetail",
        meta: { title: "园区详情", activeMenu: "/resource/park/parkmsg" },
      },
    ],
  },
  {
    path: "/resource/park/bluePrints",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "detail",
        component: () => import("@/views/configuration/park/bluePrint/components/detail"),
        name: "bluePrintdetail",
        meta: { title: "图纸详情", activeMenu: "/resource/park/bluePrint" },
      },
    ],
  },
  {
    path: "/configuration/organization/set",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "set",
        component: () => import("@/views/configuration/organization/auth/components/set"),
        name: "authorSet",
        meta: { title: "web端授权", activeMenu: "/configuration/organization/author" },
      },
    ],
  },
  {
    path: "/configuration/organization/set",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "set2",
        component: () => import("@/views/configuration/organization/auth/components/set"),
        name: "authorSet2",
        meta: { title: "驾驶舱授权", activeMenu: "/configuration/organization/author" },
      },
    ],
  },
  {
    path: "/configuration/organization/userlist",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "list",
        component: () => import("@/views/configuration/organization/role/authUser"),
        name: "authUserlist",
        meta: { title: "分配用户", activeMenu: "/configuration/organization/author" },
      },
    ],
  },
  // {
  //   path: "/work/standbook/newadds",
  //   component: Layout,
  //   hidden: true,
  //   children: [
  //     {
  //       path: "detail",
  //       component: () => import("@/views/work/accounts/newadd/components/add"),
  //       name: "newaddDetail",
  //       meta: { title: "台账详情", activeMenu: "/work/standbook/audit" },
  //     },
  //   ],
  // },
  // 本级台账新增
  {
    path: "/work/standbook/newadds",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "add",
        component: () => import("@/views/work/accounts/newadd/components/add"),
        name: "newaddAdd",
        meta: { title: "台账新增", activeMenu: "/work/standbook/newadd" },
      },
    ],
  },
  // 台账审核的详情
  {
    path: "/work/standbook/newadds",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "add2",
        component: () => import("@/views/work/accounts/newadd/components/add"),
        name: "newaddAdd",
        meta: { title: "台账审核", activeMenu: "/work/standbook/audit" },
      },
    ],
  },
  // 本级台账汇总上报详情
  {
    path: "/work/standbook/reports",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "collect",
        component: () => import("@/views/work/accounts/components/standingbook"),
        name: "standingbookCollect",
        meta: { title: "台账汇总", activeMenu: "/work/standbook/report" },
      },
    ],
  },
  // 区域台账汇总上报详情
  {
    path: "/work/standbook/reports",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "collect2",
        component: () => import("@/views/work/accounts/components/standingbook"),
        name: "standingbookCollect4",
        meta: { title: "台账汇总", activeMenu: "/work/standbook/juniorreport" },
      },
    ],
  },
  // 本级台账审核详情
  {
    path: "/work/standbook/audits",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "collect",
        component: () => import("@/views/work/accounts/components/standingbook"),
        name: "standingbookCollect2",
        meta: { title: "审核详情", activeMenu: "/work/standbook/audit" },
      },
    ],
  },
  // 区域台账审核详情
  {
    path: "/work/standbook/audits",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "collect2",
        component: () => import("@/views/work/accounts/components/standingbook"),
        name: "standingbookCollect3",
        meta: { title: "审核详情", activeMenu: "/work/standbook/junioraudit" },
      },
    ],
  },
  // 历年台账
  {
    path: "/statistics/standingbooks",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "collect",
        component: () => import("@/views/work/accounts/components/standingbook"),
        name: "standingbookCollect6",
        meta: { title: "台账详情", activeMenu: "/statistics/standingbook/standingbook" },
      },
    ],
  },
  {
    path: "/resource/park/roomUser",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "",
        component: roomUser,
        name: "roomUser",
        meta: { title: "配置用户", activeMenu: "/resource/park/roommsg" },
      },
    ],
  },
  {
    path: "/configuration/navsets",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "set",
        component: () => import("@/views/configuration/navset/components/children"),
        name: "navsetChildren",
        meta: { title: "导航页模块配置", activeMenu: "/configuration/navset" },
      },
    ],
  },
  {
    path: "/work",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "budgetSummaryList",
        component: () => import("@/views/work/budgetDeclaration/report/summaryList"),
        name: "budgetSummaryList", activeMenu: "/work/budget/budgetReport"
      },
    ],
  },
  {
    path: "/esign",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "/signaturePanel",
        component: esign,
        name: "signaturePanel",
        meta: { title: "电子签名", },
      },
    ],
  },
  {
    path: "/resource/sensingEquipment",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "detail",
        component: () => import("@/views/resource/sensingEquipment/electric/components/detail"),
        name: "electricDetail",
        meta: { title: "电表回路详情", activeMenu: "/resource/sensingEquipment/electric" },
      },
    ],
  },
  {
    path: "/resource/sensingEquipment",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "waterdetail",
        component: () => import("@/views/resource/sensingEquipment/water/components/detail"),
        name: "waterDetail",
        meta: { title: "水表详情", activeMenu: "/resource/sensingEquipment/water" },
      },
    ],
  },
  {
    path: "/resource/park/floorset",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "setdetail",
        component: () => import("@/views/configuration/park/floormsg/components/set"),
        name: "setDetail",
        meta: { title: "楼层配置", activeMenu: "/resource/park/floormsg" },
      },
    ],
  },
  {
    path: "/statistics/water/year",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "detail",
        component: () => import("@/views/statistics/water/components/detail"),
        name: "waterStadetail",
        meta: { title: "用水详情", activeMenu: "/statistics/yongnengtongji/waterS" },
      },
    ],
  },
  {
    path: "/statistics/electricity/year",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "detail",
        component: () => import("@/views/statistics/electricity/components/detail"),
        name: "electricityStadetail",
        meta: { title: "用电详情", activeMenu: "/statistics/yongnengtongji/electricityS" },
      },
    ],
  },
  {
    path: "/statistics/carbon/year",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "detail",
        component: () => import("@/views/statistics/carbon/components/detail"),
        name: "carbonStadetail",
        meta: { title: "碳排详情", activeMenu: "/statistics/carbonS" },
      },
    ],
  },
  {
    path: "/statistics",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "statisticsBudgetDetail",
        component: statisticsBudgetDetail,
        name: "statisticsBudgetDetail",
        meta: { title: "预算申报统计详情", activeMenu: "/statistics/yusuan/budgetDeclaration" },
      },
    ],
  },
  {
    path: "/statistics",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "statisticsBudgetUseDetail",
        component: statisticsBudgetUseDetail,
        name: "statisticsBudgetUseDetail",
        meta: { title: "预算申报统计详情", activeMenu: "/statistics/yusuan/budgetDeclaration" },
      },
    ],
  },
  {
    path: "/statistics/parkS/building",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "detial",
        component: () => import("@/views/statistics/park/building/components/detail"),
        name: "statisticsBuildingDetail",
        meta: { title: "楼宇用能详情", activeMenu: "/statistics/parkS/buildingstatistics" },
      },
    ],
  },
  {
    path: "/statistics/parkS/floor",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "detial",
        component: () => import("@/views/statistics/park/floor/components/detail"),
        name: "statisticsFloorDetail",
        meta: { title: "楼层用能详情", activeMenu: "/statistics/parkS/floorstatistics" },
      },
    ],
  },
  {
    path: "/statistics/parkS/dept",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "detial",
        component: () => import("@/views/statistics/park/dept/components/detail"),
        name: "statisticsDeptDetail",
        meta: { title: "单位用能详情", activeMenu: "/statistics/parkS/deptstatistics" },
      },
    ],
  }, {
    path: "/statistics/unit",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "detial",
        component: () => import("@/views/statistics/unit/detail"),
        name: "statisticsUnitDetail",
        meta: { title: "单位用能详情", activeMenu: "/statistics/yongneng/unit" },
      },
    ],
  },
  {
    path: "/statistics/water",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "day",
        component: () => import("@/views/statistics/water/day"),
        name: "waterDay",
        meta: { title: "用水详情", activeMenu: "/statistics/yongneng/waterS" },
      },
    ],
  },
  {
    path: "/statistics/carbon",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "day",
        component: () => import("@/views/statistics/carbon/day"),
        name: "carbonDay",
        meta: { title: "碳排详情", activeMenu: "/statistics/yongneng/carbonS" },
      },
    ],
  },
  {
    path: "/statistics/electricity",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "day",
        component: () => import("@/views/statistics/electricity/day"),
        name: "electricityDay",
        meta: { title: "用电详情", activeMenu: "/statistics/yongneng/electricityS" },
      },
    ],
  },
  {
    path: "/work/standbook/newadd/accountsDetail",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "",
        component: () => import("@/views/work/accounts/newadd/detail"),
        name: "accountsDetail",
        meta: { title: "基表详情", activeMenu: "/work/standbook/newadd" },
      },
    ],
  },
  {
    path: "/work/standbook/reportDetail",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "",
        component: () => import("@/views/work/accounts/report/detail"),
        name: "reportDetail",
        meta: { title: "综表详情", activeMenu: "" },
      },
    ],
  },
  // {
  //   path: "/maintenance",
  //   component: Layout,
  //   hidden: true,
  //   children: [
  //     {
  //       path: "realtime/inspect/alarmlist",
  //       component: () => import("@/views/maintenance/realtime/inspect/components/alarmList"),
  //       name: "alarmList",
  //       meta: { title: "历史预警", activeMenu: "/maintenance/realtime/inspect" },
  //     },
  //   ],
  // },
  // {
  //   path: "/maintenance",
  //   component: Layout,
  //   hidden: true,
  //   children: [
  //     {
  //       path: "realtime/inspect/alarmlist",
  //       component: () => import("@/views/maintenance/realtime/inspect/components/alarmList"),
  //       name: "alarmList2",
  //       meta: { title: "历史预警", activeMenu: "/maintenance/realtime/inspect2" },
  //     },
  //   ],
  // },
];

// 动态路由，基于用户权限动态去加载
// export const dynamicRoutes = [
//   {
//     path: '/system/user-auth',
//     component: Layout,
//     hidden: true,
//     permissions: ['system:user:edit'],
//     children: [
//       {
//         path: 'role/:userId(\\d+)',
//         component: () => import('@/views/system/user/authRole'),
//         name: 'AuthRole',
//         meta: { title: '分配角色', activeMenu: '/system/user' }
//       }
//     ]
//   },
//   {
//     path: '/system/role-auth',
//     component: Layout,
//     hidden: true,
//     permissions: ['system:role:edit'],
//     children: [
//       {
//         path: 'user/:roleId(\\d+)',
//         component: () => import('@/views/system/role/authUser'),
//         name: 'AuthUser',
//         meta: { title: '分配用户', activeMenu: '/system/role' }
//       }
//     ]
//   },
//   {
//     path: '/system/dict-data',
//     component: Layout,
//     hidden: true,
//     permissions: ['system:dict:list'],
//     children: [
//       {
//         path: 'index/:dictId(\\d+)',
//         component: () => import('@/views/system/dict/data'),
//         name: 'Data',
//         meta: { title: '字典数据', activeMenu: '/system/dict' }
//       }
//     ]
//   },
//   {
//     path: '/monitor/job-log',
//     component: Layout,
//     hidden: true,
//     permissions: ['monitor:job:list'],
//     children: [
//       {
//         path: 'index',
//         component: () => import('@/views/monitor/job/log'),
//         name: 'JobLog',
//         meta: { title: '调度日志', activeMenu: '/monitor/job' }
//       }
//     ]
//   },
//   {
//     path: '/tool/gen-edit',
//     component: Layout,
//     hidden: true,
//     permissions: ['tool:gen:edit'],
//     children: [
//       {
//         path: 'index/:tableId(\\d+)',
//         component: () => import('@/views/tool/gen/editTable'),
//         name: 'GenEdit',
//         meta: { title: '修改生成配置', activeMenu: '/tool/gen' }
//       }
//     ]
//   }
// ];

// 防止连续点击多次路由报错
// let routerPush = Router.prototype.push;
// Router.prototype.push = function push(location) {
//   return routerPush.call(this, location).catch(err => err)
// }

export default new Router({
  mode: "history", // 去掉url中的#
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes,
});
